<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="#">系统管理</a>
        </li>

        <li>
            <a href="#">系统配置管理</a>
        </li>
    </ul>
    <div>
        <input type="hidden" id="cupage" value="1"/>
        <input type="hidden" id="total" value="1"/>
        <input type="hidden" id="formurl" value="/manager/system/getSystemConfigPage"/>
    </div>
</div>

<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="icon-reorder"></i>
                        筛选条件
                    </h3>
                </div>
                <div class="panel-body">
                    <form class="form-horizontal">
                    <label for="status" class="col-sm-1 control-label">菜单名称:</label>
                    <div class="col-md-2">
                        <input type="text" class="form-control" id="status" placeholder="请输入查询条件">
                    </div>
                    <div class="col-md-1">
                        <input type="button" id="btn-load" class="btn btn-primary btn-pikaqiu" data-loading-text="加载中..." value="查 询"/>
                    </div>
                    </form>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="icon-reorder"></i>
                        系统配置管理
                    </h3>
                    <div class="btn-add-pikaqiu">
                        <button class="btn btn-xs" data-toggle="modal" data-target="#systemConfigAddModal"><i class="icon-plus"></i> 添 加</button>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>一级推荐奖励</th>
                                <th>二级推荐奖励</th>
                                <th>vip购买价格</th>
                                <th>vip购买标题</th>
                                <th>是否免费体验</th>
                                <th>创建人</th>
                                <th>创建时间</th>
                                <th>状态</th>
                            </tr>
                            </thead>

                            <tbody id="loadData">

                            </tbody>
                        </table>
                        <!--#include file="/admin/include/page.html"-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="systemConfigAddModal" tabindex="-1" role="dialog" aria-labelledby="systemConfigAddModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">新增系统配置</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form" id="menuForm">
                    <div class="form-group">
                        <label for="referer_reward_first" class="col-sm-3 control-label">一级推荐奖励</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="referer_reward_first">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="referer_reward_second" class="col-sm-3 control-label">二级推荐奖励</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="referer_reward_second">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="vip_price" class="col-sm-3 control-label">vip购买价格</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="vip_price">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="vip_title" class="col-sm-3 control-label">vip购买标题</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="vip_title" placeholder="支付宝购买时展示的标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="is_free" class="col-sm-3 control-label">开启免费体验</label>
                        <div class="col-xs-3" id="is_free">
                            <input name="is_free" class="ace" value="0" type="radio" checked="checked">
                            <span class="lbl"> 否 </span>
                            <input name="is_free" class="ace" value="1" type="radio">
                            <span class="lbl"> 是 </span>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="addSystemConfig()">提交更改</button>
            </div>
        </div>
    </div>
</div>


<script>
    $("#btn-load").on("click", function () {
        var a = $(this);
        a.button("loading");
        $("#cupage").val("1");
        loadData();
    });

    function loadData() {
        var status = $("#status").val();
        var para = {
            curPage: $("#cupage").val(),
            status: status
        };
        loadGetServer($("#formurl").val(), para, function (data) {
            var $loadData = $("#loadData");
            $loadData.html("");
            var list = data.page.list;
            var html_ = "";
            for (var i = 0; i < list.length; i++) {
                html_ += "<tr><td>" + list[i].referer_reward_first + "</td><td>" + list[i].referer_reward_second + "</td><td>" + list[i].vip_price + "</td>";
                html_ += "<td>" + list[i].vip_title + "</td>";
                if(list[i].is_free===0){
                    html_ += "<td>否</td>";
                }else{
                    html_ += "<td>是</td>";
                }
                html_ +=  "<td>" + list[i].create_by + "</td><td>" + list[i].create_date + "</td>";
                if(list[i].status===0){
                    html_ += "<td><span class='label label-sm label-success'>正常</span></td>";
                }else{
                    html_ += "<td><span class='label label-sm label-warning'>失效</span></td>";
                }
                html_ += "</tr>";
            }
            $loadData.html(html_);
            pageValue(data);
            pageData();
            $("#btn-load").button("reset");
        });
    }

    loadData();

    $('#systemConfigAddModal').on('show.bs.modal', function () {
        $("#menuForm")[0].reset();
        loadGetServer('/manager/system/getLastSystemConfig', {}, function (data) {
            var systemConfig = data.systemConfig;
            if(systemConfig != null){
                $("#referer_reward_first").val(systemConfig.referer_reward_first);
                $("#referer_reward_second").val(systemConfig.referer_reward_second);
                $("#vip_price").val(systemConfig.vip_price);
                $("#vip_title").val(systemConfig.vip_title);
                $("#is_free input[value=" + data.data.is_free + "]").prop("checked", true);
            }
        });
    })

    function addSystemConfig(){
        var para = {
            referer_reward_first: $("#referer_reward_first").val(),
            referer_reward_second: $("#referer_reward_second").val(),
            vip_price: $("#vip_price").val(),
            vip_title: $("#vip_title").val(),
            is_free : $("#is_free input:radio[name='is_free']:checked").val()
        };
        loadGetServer('/manager/system/addSystemConfig', para, function (data) {
            if(data.code != 0){
                alert(data.msg);
            }else{
                alert('操作成功')
                $('#systemConfigAddModal').modal('hide');
            }
            loadData();
        });
    }
</script>